package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.service.StoreService;
import com.tarena.lbs.pojo.basic.param.StoreParam;
import com.tarena.lbs.pojo.basic.query.AreaStoreQuery;
import com.tarena.lbs.pojo.basic.query.StoreQuery;
import com.tarena.lbs.pojo.basic.vo.StoreVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class StoreController {
    @Autowired
    private StoreService storeService;
    @PostMapping("/admin/basic/store/getAll")
    public Result<PageResult<StoreVO>> storePage(@RequestBody StoreQuery storeQuery)
        throws BusinessException {
        return new Result<>(storeService.storePage(storeQuery));
    }
    //新增提交店铺表单
    @PostMapping("/admin/basic/store/add")
    public Result<Void> save(@RequestBody StoreParam param) throws BusinessException{
        storeService.save(param);
        return Result.success();
    }
    //根据城市区域树 查询当前登录账号所属商家的店铺
    @PostMapping("/admin/basic/store/getStoreByCity")
    public Result<PageResult<StoreVO>> cityStores(@RequestBody AreaStoreQuery areaStoreQuery)
        throws BusinessException{
        return new Result<>(storeService.cityStores(areaStoreQuery));
    }
}
